package logic

import (
	"Junior_two/subject/usercenter/userrpc/internal/utils"
	"context"
	"net/http"
	"strconv"

	"Junior_two/subject/usercenter/userrpc/internal/svc"
	"Junior_two/subject/usercenter/userrpc/pb/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type AuthLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAuthLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AuthLogic {
	return &AuthLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AuthLogic) Auth(in *user.AuRequest) (*user.AuResponse, error) {
	// todo: add your logic here and delete this line
	m, e := utils.CardTest(in.RealName, in.IdCard)
	if e != nil {
		return &user.AuResponse{
			Msg:  e.Error(),
			Code: http.StatusAccepted,
		}, nil
	}
	intCode, _ := strconv.Atoi(m["code"].(string))
	if m["code"] != "0" {
		return &user.AuResponse{
			Msg:  m["message"].(string),
			Code: int64(intCode),
		}, nil
	}
	return &user.AuResponse{
		Msg:  m["message"].(string),
		Code: http.StatusOK,
	}, nil
}
